package com.miku.blog.controller;

import com.miku.blog.annotation.SystemLog;
import com.miku.blog.domain.pojo.ResponseResult;
import com.miku.blog.domain.pojo.SystemConstance;
import com.miku.blog.service.LikeCountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author shkstart
 * @create ${}YEAR-06-15 6:47
 */
@Api(tags = "Blog[点赞]")
@RestController
public class LikeCountController {

    @Autowired
    private LikeCountService likeCountService;


    @SystemLog(notes = "添加/删除文章点赞数据{前台博客系统}")
    @ApiOperation(value = "添加/删除文章点赞数据接口",notes = "根据文章ID 、 是否已点赞 及 执行此操作的用户ID 判断是添加还是删除点赞数据")
    @PostMapping("/like/articles/{articleId}/{isLike}")
    public ResponseResult addArticleLikeCountById(@PathVariable("articleId") Integer articleId,
                                                  @PathVariable("isLike") Integer isLike)
    {
        return likeCountService.addLikeCountByIdAndIsLikeAndType(articleId,isLike, SystemConstance.LIKE_COUNT_TYPE_BY_ARTICLE);
    }


    @SystemLog(notes = "添加/删除说说点赞数据{前台博客系统}")
    @ApiOperation(value = "添加/删除说说点赞数据接口",notes = "根据说说ID 、 是否已点赞 及 执行此操作的用户ID 判断是添加还是删除点赞数据")
    @PostMapping("/like/talks/{talkId}/{isLike}")
    public ResponseResult addTalkLikeCountById(@PathVariable("talkId") Integer talkId,
                                               @PathVariable("isLike") Integer isLike)
    {
        return likeCountService.addLikeCountByIdAndIsLikeAndType(talkId,isLike,SystemConstance.LIKE_COUNT_TYPE_BY_TALK);
    }

    @SystemLog(notes = "添加/删除评论点赞数据{前台博客系统}")
    @ApiOperation(value = "添加/删除评论点赞数据接口",notes = "根据评论ID 、 是否已点赞 及 执行此操作的用户ID 判断是添加还是删除点赞数据")
    @PostMapping("/like/comments/{commentId}/{isLike}")
    public ResponseResult addCommentLikeCountById(@PathVariable("commentId") Integer commentId,
                                                  @PathVariable("isLike") Integer isLike)
    {
        return likeCountService.addLikeCountByIdAndIsLikeAndType(commentId,isLike,SystemConstance.LIKE_COUNT_TYPE_BY_COMMENT);
    }

}
